/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ch.hslu.prg2.team2.gui;

import ch.hslu.prg2.team2.logic.ComputerPlayer;
import ch.hslu.prg2.team2.logic.RandomComputerPlayer;
import ch.hslu.prg2.team2.logic.AwareComputerPlayer;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
/**
 *
 * @author Claudio
 */
public class OpponentChangeDialog extends JDialog
{
    private final JComboBox opponent;
    private IComputerPlayerChanged computerPlayerChangedListener;
    
    public OpponentChangeDialog(JFrame owner)
    {        
        super(owner);
        
        opponent = new JComboBox();
        opponent.setSize(140,26);
        opponent.addItem(new RandomComputerPlayer("Test"));
        opponent.addItem(new AwareComputerPlayer("Test"));        
        
        JButton buttonOk = new JButton("OK");
        buttonOk.addActionListener(new ButtonOkListener());
        buttonOk.setSize(80, 26 );
        
        JButton buttonAbort = new JButton("Abbrechen");
        buttonAbort.addActionListener(new ButtonAbortListener());
        buttonAbort.setSize(80, 26 );
                
        getContentPane().add(opponent);
        getContentPane().add(buttonOk);
        getContentPane().add(buttonAbort);
        getContentPane().setLayout(new FlowLayout());
        
        setTitle("Computerspieler anpassen");
        setSize(400,70);
        setResizable(false);
        setLocation(500,300);
    }
    
    public void setComputerPlayerChangedListener( IComputerPlayerChanged actionListener )
    {
        this.computerPlayerChangedListener = actionListener;
    }
    
    public class ButtonOkListener implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            if( computerPlayerChangedListener != null )
            {
                computerPlayerChangedListener.computerPlayerChanged((ComputerPlayer)opponent.getSelectedItem());
            }
            setVisible(false);
        }        
    }
    
    public class ButtonAbortListener implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            setVisible(false);
        }
    }
}
